/**
 */
package com.dingpeikeji.quickdeer.core.modules.orders.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.dingpeikeji.quickdeer.core.common.config.Global;
import com.dingpeikeji.quickdeer.core.common.persistence.Page;
import com.dingpeikeji.quickdeer.core.common.utils.StringUtils;
import com.dingpeikeji.quickdeer.core.common.web.BaseController;
import com.dingpeikeji.quickdeer.core.modules.orders.entity.TOrdersOut;
import com.dingpeikeji.quickdeer.core.modules.orders.service.TOrdersOutService;

/**
 * 退款通知Controller
 * @author isouland
 * @version 2016-07-14
 */
@Controller
@RequestMapping(value = "${adminPath}/order/tOrdersOut")
public class TOrdersOutController extends BaseController {

	@Autowired
	private TOrdersOutService tOrdersOutService;
	
	@ModelAttribute
	public TOrdersOut get(@RequestParam(required=false) String outid) {
		TOrdersOut entity = null;
		if (StringUtils.isNotBlank(outid)){
			entity = tOrdersOutService.get(outid);
		}
		if (entity == null){
			entity = new TOrdersOut();
		}
		return entity;
	}
	
	@RequiresPermissions("order:tOrdersOut:view")
	@RequestMapping(value = {"list", ""})
	public String list(TOrdersOut tOrdersOut, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TOrdersOut> page = tOrdersOutService.findPage(new Page<TOrdersOut>(request, response), tOrdersOut); 
		model.addAttribute("page", page);
		return "modules/orders/tOrdersOutList";
	}

	@RequiresPermissions("order:tOrdersOut:view")
	@RequestMapping(value = "form")
	public String form(TOrdersOut tOrdersOut, Model model) {
		model.addAttribute("tOrdersOut", tOrdersOut);
		return "modules/orders/tOrdersOutForm";
	}

	@RequiresPermissions("order:tOrdersOut:edit")
	@RequestMapping(value = "save")
	public String save(TOrdersOut tOrdersOut, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tOrdersOut)){
			return form(tOrdersOut, model);
		}
		tOrdersOutService.save(tOrdersOut);
		addMessage(redirectAttributes, "保存退款通知成功");
		return "redirect:"+Global.getAdminPath()+"/order/tOrdersOut/?repage";
	}
	
	@RequiresPermissions("order:tOrdersOut:edit")
	@RequestMapping(value = "delete")
	public String delete(TOrdersOut tOrdersOut, RedirectAttributes redirectAttributes) {
		tOrdersOutService.delete(tOrdersOut);
		addMessage(redirectAttributes, "删除退款通知成功");
		return "redirect:"+Global.getAdminPath()+"/order/tOrdersOut/?repage";
	}

}
